from pages.basePage4 import BasePage
from config.setting import host_port
import time

# 元素定位层
class VehicePage(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        time.sleep(2)
        self.driver.get(f"http://{host_port}/SharedParkingPlace/admin/index.html")

    # 车辆相关
    def vehicle_related(self):
        return self.driver.find_element_by_xpath('//div[@id="sm"]/div[1]/div[1]/div[1]/div[1]')
    # 车位管理
    def pick_lot(self):
        return self.driver.find_element_by_xpath('//div[@id="_easyui_tree_1"]/span[3]')
    # 定位表单
    def iframe(self):
        return self.driver.find_element_by_id('testIframe')
    # 定位位置ID搜索框
    def locationid(self):
        return self.driver.find_element_by_xpath('//input[@id="locationid"]')
    # 定位车位ID搜索框
    def parkingsizeid(self):
        return self.driver.find_element_by_xpath('//input[@id="parkingsizeid"]').send_keys()
    # 定位车位主id搜索框
    def uid(self):
        return self.driver.find_element_by_xpath('//input[@id="uid"]')
    # 定位车位状态搜索框
    def parkingstatus(self):
        return self.driver.find_element_by_xpath('//input[@id="parkingstatus"]')

    # 定位增加按钮
    def add(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[1]/span')
    # 定位位置ID
    def position(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input1"]')
    #定位车位大小ID
    def pick_lot_size(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input2"]')
    # 定位车位主ID()
    def pick_lot_id(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位详细地址
    def address(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input4"]')
    # 车位状态
    def pick_lot_state(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input5"]')
    # 车位号
    def pick_num(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input6"]')
    # 点击新增确定
    def confirm(self):
        return self.driver.find_element_by_xpath('//div[@id="dlg-buttons"]/a[1]')
    #勾选框
    def Check(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]')
    # 定位删除
    def del_veh(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[2]/span')
    # 定位修改
    def mondfiy(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[3]/span')
    # 定位查询框
    def search(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[4]/span')

    # 点击新增确定
    def md_confirm(self):
        return self.driver.find_element_by_xpath('//div[@id="dlg-buttons"]/a[2]')

    # 定位弹出框
    def Popup(self):
        return self.driver.find_element_by_xpath('//body/div[5]/div[@class="messager-body panel-body panel-body-noborder window-body"]')

#操作层
class VehicleHandle(VehicePage):

    def __init__(self):
        VehicePage.__init__(self)
    # 点击车辆相关
    def click_vehicle(self):
        self.vehicle_related().click()
    # 点击车位管理
    def  click_pick(self):
        self.pick_lot().click()
    # 切换表单
    def  swith_frame(self):
        a =self.iframe()
        return self.driver.switch_to.frame(a)
    # 点击新增
    def add_clk(self):
        self.add().click()
    # 点击修改
    def mondfiy_clk(self):
        self.mondfiy().click()
    # 输入位置ID
    def send_position(self,positionid):
        input1=self.position()
        input1.clear()
        input1.send_keys(positionid)
    # 输入车位大小ID
    def send_size(self,size):
        input2=self.pick_lot_size()
        input2.clear()
        input2.send_keys(size)
    # 输入车位主ID
    def send_pick_id(self,pickid):
        input3=self.pick_lot_id()
        input3.clear()
        input3.send_keys(pickid)
    #输入详细地址
    def send_address(self,address):
        input4=self.address()
        input4.clear()
        input4.send_keys(address)
    # 输入车位状态
    def send_pick_lot_state(self,state):
        input5=self.pick_lot_state()
        input5.clear()
        input5.send_keys(state)
    # 输入车位号
    def send_pick_num(self,num):
        input6=self.pick_num()
        input6.clear()
        input6.send_keys(num)
    # 点击新增确定
    def click_confirm(self):
        self.confirm().click()
    def click_mdconfirm(self):
        self.md_confirm().click()
    # 勾选框选择
    def  click_check(self):
        self.Check().click()
    def check_text(self):
        text1=self.Check().text
        return text1
    # 点击删除
    def click_del(self):
        self.del_veh().click()
    # 获取文本信息
    def get_text(self):
        result = self.Popup().text
        return result
    # 输入位置ID
    def send_locationid(self,id):
        self.locationid().send_keys(id)
    # 输入车位id
    def send_parkingsizeid(self,pid):
        self.parkingsizeid().send_keys(pid)
#     输入车位主ID
    def send_uid(self,uid):
        self.uid().send_keys(uid)
    # 输入车位状态
    def send_parkingstatus(self,parkingstatus):
        self.parkingstatus().send_keys(parkingstatus)
    # 点击查询
    def click_search(self):
        self.search().click()


class VehicleBusiness(VehicleHandle):
    def __init__(self):
        VehicleHandle.__init__(self)
     # 删除车位信息
    def del_Vehicle(self):
        self.click_vehicle()
        self.click_pick()
        self.swith_frame()
        self.click_check()
        self.click_del()
        result =self.get_text()
        time.sleep(2)
        return  result
    # 新增车位信息
    def new_parking_information(self,positionid,size,pickid,address,state,num):
        """

        :param positionid: 位置ID
        :param size: 车位大小ID
        :param pickid: 车位主ID
        :param address: 地址
        :param state: 车位状态
        :param num: 车位号
        :return:
        """
        self.click_vehicle()
        self.click_pick()
        self.swith_frame()
        time.sleep(2)
        self.add_clk()
        self.send_position(positionid)
        self.send_size(size)
        self.send_pick_id(pickid)
        self.send_address(address)
        self.send_pick_lot_state(state)
        self.send_pick_num(num)
        self.click_confirm()
        time.sleep(2)
        return self.get_text()
  # 修改车位信息
    def modify_parking(self,positionid,size,pickid,address,state,num):
        """

        :param positionid: 位置ID
        :param size: 车位大小ID
        :param pickid: 车位主ID
        :param address: 地址
        :param state: 车位状态
        :param num: 车位号
        :return:
        """
        self.click_vehicle()
        self.click_pick()
        self.swith_frame()
        time.sleep(2)
        self.click_check()
        self.mondfiy_clk()
        self.send_position(positionid)
        self.send_size(size)
        self.send_pick_id(pickid)
        self.send_address(address)
        self.send_pick_lot_state(state)
        self.send_pick_num(num)
        self.click_mdconfirm()
        time.sleep(2)
        return self.get_text()



if __name__ == '__main__':
    a =VehicleBusiness()
    # r =a.del_Vehicle()
    y=a.new_parking_information(4040,1,'6ade98f4-a14c-4bf0-a993-8ca936030245','太平天国123',1,1)
    # z =a.modify_parking(4444,1,'6ade98f4-a14c-4bf0-a993-8ca936030245','太平天国洪秀全',1,1)
    print(y)
